var ms_library = require('ms-common-library');
module.exports = function (UC, source, config, ArFor, cache) {
    var UserControl = UC;
    var router = function () {
        this.install = true;
        this.name = "Products_Print_Server";
        var off = true;
        var List = [];
        var start = function () {
            if (off && List.length > 0) {
                var msLibrary = config.msLibrary();
                off = false;
                var Request = List[0]
                var printer = msLibrary.printer(Request.url);
                var Callback = function (obj) {
                    off = true;
                    List.shift(0, 1);
                    Request.Callback(obj)
                    start()
                }
                printer.then(function (code, jsondb) {
                    if (code == 0) {
                        if (jsondb && jsondb.error > -1) {
                            Callback(jsondb);
                        } else {
                            Callback({
                                "error": 4
                            });
                        }
                    } else {
                        Callback({
                            "error": 5
                        });
                    }
                })
            }
        }
        this.add = function (url, Callback) {
            // off = List.length == 0;
            List.push({
                url: url,
                Callback: Callback
            });
            start();
        }
        this.geterror = function () {

        }
    };
    return new router;
};